package com.ruoyi.HKISAPI.controller;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@RequestMapping("/ISAPI")
@Controller
public class ImageController {

    private static final String IMAGE_ROOT = "/Users/wangxiaoxing/Desktop/sql/";

    @GetMapping("/image/{imageName:.+}")
    public ResponseEntity<byte[]> getImage(@PathVariable String imageName) throws IOException {
        Path imagePath = Paths.get(IMAGE_ROOT, imageName);

        byte[] imageData = Files.readAllBytes(imagePath);

        return ResponseEntity.ok()
                .contentType(MediaType.IMAGE_JPEG) // 根据实际图片类型设置MediaType
                .body(imageData);
    }


    public ResponseEntity<byte[]> getImage2(@PathVariable String imageName) throws IOException {


        Path imagePath = Paths.get(IMAGE_ROOT, imageName);

        byte[] imageData = Files.readAllBytes(imagePath);

        return ResponseEntity.ok()
                .contentType(MediaType.IMAGE_JPEG) // 根据实际图片类型设置MediaType
                .body(imageData);
    }


}
